package com.castile.secondkill.validator;

import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * 校验的结果类
 *
 * @author Hongliang Zhu
 * @create 2023-03-05 21:41
 */
public class ValidationResult {
    /**
     * 检验结果是否有错误
     */
    private boolean hasError = false;

    /**
     * 校验的错误信息
     */
    private Map<String, String> errorMsg = new HashMap<>();

    public ValidationResult(boolean hasError, Map<String, String> errorMsg) {
        this.hasError = hasError;
        this.errorMsg = errorMsg;
    }

    public ValidationResult() {
    }

    public boolean isHasError() {
        return hasError;
    }

    public void setHasError(boolean hasError) {
        this.hasError = hasError;
    }

    public void setErrorMsg(Map<String, String> errorMsg) {
        this.errorMsg = errorMsg;
    }

    public Map<String, String> getErrorMsgMap() {
        return this.errorMsg;
    }

    /**
     * 定义通用的通过格式化字符串信息获取错误结果的msg方法
     *
     * @return 错误信息
     */
    public String getErrorMsg() {
        return StringUtils.join(errorMsg.values().toArray(), ",");
    }

}
